/**
 */
package OBSL.impl;

import OBSL.OBSLPackage;
import OBSL.Situation;
import OBSL.SubParameter;
import OBSL.SubSituation;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Sub Situation</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link OBSL.impl.SubSituationImpl#getSupersituation <em>Supersituation</em>}</li>
 *   <li>{@link OBSL.impl.SubSituationImpl#getParameters <em>Parameters</em>}</li>
 *   <li>{@link OBSL.impl.SubSituationImpl#isObtains <em>Obtains</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SubSituationImpl extends SituationImpl implements SubSituation {
	/**
	 * The cached value of the '{@link #getParameters() <em>Parameters</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParameters()
	 * @generated
	 * @ordered
	 */
	protected EList<SubParameter> parameters;

	/**
	 * The default value of the '{@link #isObtains() <em>Obtains</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isObtains()
	 * @generated
	 * @ordered
	 */
	protected static final boolean OBTAINS_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isObtains() <em>Obtains</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isObtains()
	 * @generated
	 * @ordered
	 */
	protected boolean obtains = OBTAINS_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SubSituationImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return OBSLPackage.Literals.SUB_SITUATION;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Situation getSupersituation() {
		if (eContainerFeatureID() != OBSLPackage.SUB_SITUATION__SUPERSITUATION) return null;
		return (Situation)eInternalContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetSupersituation(Situation newSupersituation, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newSupersituation, OBSLPackage.SUB_SITUATION__SUPERSITUATION, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSupersituation(Situation newSupersituation) {
		if (newSupersituation != eInternalContainer() || (eContainerFeatureID() != OBSLPackage.SUB_SITUATION__SUPERSITUATION && newSupersituation != null)) {
			if (EcoreUtil.isAncestor(this, newSupersituation))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newSupersituation != null)
				msgs = ((InternalEObject)newSupersituation).eInverseAdd(this, OBSLPackage.SITUATION__SUBSITUATIONS, Situation.class, msgs);
			msgs = basicSetSupersituation(newSupersituation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.SUB_SITUATION__SUPERSITUATION, newSupersituation, newSupersituation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SubParameter> getParameters() {
		if (parameters == null) {
			parameters = new EObjectContainmentEList<SubParameter>(SubParameter.class, this, OBSLPackage.SUB_SITUATION__PARAMETERS);
		}
		return parameters;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isObtains() {
		return obtains;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setObtains(boolean newObtains) {
		boolean oldObtains = obtains;
		obtains = newObtains;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, OBSLPackage.SUB_SITUATION__OBTAINS, oldObtains, obtains));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetSupersituation((Situation)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				return basicSetSupersituation(null, msgs);
			case OBSLPackage.SUB_SITUATION__PARAMETERS:
				return ((InternalEList<?>)getParameters()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				return eInternalContainer().eInverseRemove(this, OBSLPackage.SITUATION__SUBSITUATIONS, Situation.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				return getSupersituation();
			case OBSLPackage.SUB_SITUATION__PARAMETERS:
				return getParameters();
			case OBSLPackage.SUB_SITUATION__OBTAINS:
				return isObtains();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				setSupersituation((Situation)newValue);
				return;
			case OBSLPackage.SUB_SITUATION__PARAMETERS:
				getParameters().clear();
				getParameters().addAll((Collection<? extends SubParameter>)newValue);
				return;
			case OBSLPackage.SUB_SITUATION__OBTAINS:
				setObtains((Boolean)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				setSupersituation((Situation)null);
				return;
			case OBSLPackage.SUB_SITUATION__PARAMETERS:
				getParameters().clear();
				return;
			case OBSLPackage.SUB_SITUATION__OBTAINS:
				setObtains(OBTAINS_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case OBSLPackage.SUB_SITUATION__SUPERSITUATION:
				return getSupersituation() != null;
			case OBSLPackage.SUB_SITUATION__PARAMETERS:
				return parameters != null && !parameters.isEmpty();
			case OBSLPackage.SUB_SITUATION__OBTAINS:
				return obtains != OBTAINS_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (obtains: ");
		result.append(obtains);
		result.append(')');
		return result.toString();
	}

} //SubSituationImpl
